home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / win2maccountersamples / 4. counterdocument / source / ccounterapp.cp next >
Encoding:
Text File  |  2000-09-28  |  3.7 KB  |  131 lines

  1. /*
  2.     File:        CCounterApp.cp
  3.  
  4.     Contains:    Sample code to accompany Chapter 12 of 
  5.                 "An Introduction to Macintosh Programming for Windows Programmers".
  6.                 
  7.     Written by:    Worldwide Developer Technical Support
  8.  
  9.     Copyright:    1999 Apple Computer, Inc., All Rights Reserved
  10.  
  11.       You may incorporate this sample code into your applications without
  12.       restriction, though the sample code has been provided "AS IS" and the
  13.       responsibility for its operation is 100% yours.  However, what you are
  14.       not permitted to do is to redistribute the source as "DSC Sample Code"
  15.       after having made changes. If you're going to re-distribute the source,
  16.      we require that you make it clear in the source that the code was
  17.     descended from Apple Sample Code, but that you've made changes.
  18.     
  19. */
  20.  
  21. #include "CCounterApp.h"
  22. #include "CounterConstants.h"
  23. #include "CCounterDocument.h"
  24. #include <LSIOUXAttachment.h>
  25. #include <iostream.h>
  26.  
  27. #include <LStaticText.h>
  28.  
  29. #include <LGrowZone.h>
  30. #include <LWindow.h>
  31. #include <PP_Messages.h>
  32. #include <PP_Resources.h>
  33. #include <PPobClasses.h>
  34. #include <UDrawingState.h>
  35. #include <UMemoryMgr.h>
  36. #include <URegistrar.h>
  37. #include <UModalDialogs.h>
  38.  
  39. #include <UControlRegistry.h>
  40. #include <UGraphicUtils.h>
  41. #include <UEnvironment.h>
  42.  
  43. #ifndef __APPEARANCE__
  44. #include <Appearance.h>
  45. #endif
  46.  
  47. #include <Sound.h>
  48. #include <ToolUtils.h>
  49.  
  50. // ===========================================================================
  51. int main()
  52. {
  53.     SetDebugThrow_(debugAction_Alert);
  54.     SetDebugSignal_(debugAction_Alert);
  55.     InitializeHeap(3);                    // allocate 3 Master Pointer blocks
  56.     UQDGlobals::InitializeToolbox(&qd);
  57.     UEnvironment::InitEnvironment();
  58.     new LGrowZone(20000);            // For low memory situations.
  59.     CCounterApp    theApp;            // stack allocation
  60.     theApp.Run();
  61.     return 0;
  62. }
  63.  
  64. // ---------------------------------------------------------------------------
  65. CCounterApp::CCounterApp()
  66. {
  67.     if ( UEnvironment::HasFeature( env_HasAppearance ) ) {
  68.         ::RegisterAppearanceClient();
  69.     }
  70.     RegisterAllPPClasses();    // functions to create core PowerPlant classes
  71.     UControlRegistry::RegisterClasses();    // Appearance Manager/GA classes
  72.     AddAttachment(new LSIOUXAttachment);    // Use SIOUX Attachment
  73. }
  74.  
  75.  
  76. // ---------------------------------------------------------------------------
  77. CCounterApp::~CCounterApp()
  78. {
  79. }
  80.  
  81. // ---------------------------------------------------------------------------
  82. //    This function lets you do something when the application starts up
  83. //    without a document.
  84. void
  85. CCounterApp::StartUp()
  86. {
  87.     ObeyCommand(cmd_New, nil);
  88. }
  89.  
  90. // ---------------------------------------------------------------------------------
  91. void
  92. CCounterApp::OpenDocument(FSSpec* inMacFSSpec )
  93. {
  94.     LDocument* theDoc = LDocument::FindByFileSpec(*inMacFSSpec);
  95.     if (theDoc != nil) {                // Document is already open
  96.         theDoc->MakeCurrent();            // Make it the current document
  97.     } else {                            // Make a new Document
  98.         theDoc = new CCounterDocument(this, inMacFSSpec);
  99.     }
  100. }
  101.  
  102. // ---------------------------------------------------------------------------------
  103. LModelObject*
  104. CCounterApp::MakeNewDocument()
  105. {
  106.     FSSpec* spec = nil;
  107.     return new CCounterDocument(this, spec);
  108. }
  109.  
  110. // ---------------------------------------------------------------------------------
  111. void
  112. CCounterApp::ChooseDocument()
  113. {
  114.     UDesktop::Deactivate();
  115.     SFTypeList            theTypeList = {kDocType};
  116.     StandardFileReply    theReply;
  117.     ::StandardGetFile( nil, 1, theTypeList, &theReply );
  118.     UDesktop::Activate();
  119.     if (theReply.sfGood) {                // if not canceled
  120.         SendAEOpenDoc(theReply.sfFile);    // send AppleEvent to open the document
  121.     }
  122. }
  123.  
  124. // ---------------------------------------------------------------------------------
  125. void
  126. CCounterApp::PrintDocument(FSSpec* inMacFSSpec )
  127. {
  128.     CCounterDocument* theDocument = new CCounterDocument(this, inMacFSSpec);
  129.     theDocument->DoPrint();
  130. }
  131.